#初始化参数信息
NginxPath="/data/nginx"

echo "Nginx部署路径:"${NginxPath}

#将文件路径切换到 Nginx Path
cd $NginxPath

#检查日志备份文件夹是否存在
if [ ! -d logs_bak  ];then
  mkdir logs_bak
else
  echo "日志备份文件夹已经存在"
  # 查找logs_bakx下7天前的文件夹或文件并删除
  find ./logs_bak -mtime +7 -name "*.*" -exec rm -Rf {} \;
  echo "查找logs_bak下7天前的文件夹或文件并删除完成..."
fi

#将日志打包备份至日志备份文件夹
rebootVersion=`date +%Y%m%d-%H%M%S`
logsfile=logs_bak_${rebootVersion}.tar.gz
echo "将日志打包备份至日志备份文件夹:"${logsfile}

tar -Pzcf $logsfile ${NginxPath}/logs/*
mv $logsfile ${NginxPath}/logs_bak/
echo "日志文件备份完成..."

#清空现有日志文件
rm -rf $NginxPath/logs/*

#静默方式启动Tomcat
systemctl restart nginx

echo "Nginx 启动完成,等待输出日志..."

#检查启动日志是否输出,输出后Tail方式打开
tail -F $NginxPath/logs/*.*